/*
	Copyright (c) 2009, SpLib.net
  	All rights reserved.
  	
  	Author:6spring
  	About:网络消息地址
*/

package SpLib.Net
{
	public class GNID
	{
		public var m_nServiceID:uint;		//服务ID
		public var m_nGroupID:uint;			//网络组ID
		public var m_nObjIDH:uint;			//对象ID高位
		public var m_nObjIDL:uint;			//对象ID低位
		
		public function GNID(source:Array=null)
		{
			if(source!=null)
			{
				m_nServiceID = source[0];
				m_nGroupID = source[1];
				m_nObjIDH = source[2];
				m_nObjIDL = source[3];
			}
			else
			{
				m_nServiceID = 0;
				m_nGroupID = 0;
				m_nObjIDH = 0;
				m_nObjIDL = 0;
			}	
		}
		
		public function clone():GNID
		{
			var gnid:GNID = new GNID(GetAsArray());
			return gnid;
		}
		
		public function Clear():void
		{
			m_nServiceID = 0;
			m_nGroupID = 0;
			m_nObjIDH = 0;
			m_nObjIDL = 0;
		}
		
		public function SetAsArray(source:Array):void
		{
			m_nServiceID = source[0];
			m_nGroupID = source[1];
			m_nObjIDH = source[2];
			m_nObjIDL = source[3];
		}
		
		public function GetAsArray():Array
		{
			return [m_nServiceID,m_nGroupID,m_nObjIDH,m_nObjIDL];
		}

		public function IsEmpty():Boolean
		{
			return (m_nServiceID==0 && m_nGroupID==0 && m_nObjIDH==0 && m_nObjIDL==0);
		}
		
	
		public function toString():String
		{
			return "GNID[" + m_nServiceID + "," + m_nGroupID + "," + m_nObjIDH + "," + m_nObjIDL + "]";
		}
		
		public function like(rhs:GNID):Boolean
		{
			return m_nServiceID==rhs.m_nServiceID
					&& m_nGroupID==rhs.m_nGroupID;
		}
		
		public function equal(rhs:GNID):Boolean
		{
			return m_nServiceID==rhs.m_nServiceID
					&& m_nGroupID==rhs.m_nGroupID
					&& m_nObjIDH==rhs.m_nObjIDH
					&& m_nObjIDL==rhs.m_nObjIDL;
		}
		
		static public function compare(rh1:GNID,rh2:GNID):int
		{
			if(rh1.m_nServiceID>rh2.m_nServiceID) return 1;
			if(rh1.m_nServiceID<rh2.m_nServiceID) return -1;
			
			if(rh1.m_nGroupID>rh2.m_nGroupID) return 1;
			if(rh1.m_nGroupID<rh2.m_nGroupID) return -1;
			
			if(rh1.m_nObjIDH>rh2.m_nObjIDH) return 1;
			if(rh1.m_nObjIDH<rh2.m_nObjIDH) return -1;
			
			if(rh1.m_nObjIDL>rh2.m_nObjIDL) return 1;
			if(rh1.m_nObjIDL<rh2.m_nObjIDL) return -1;
			
			return 0;
		}
	}
}